<?php
class MReport extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }
    
    function getStaffBySalaryIncreaseThisMonth(){
         $data = array();
	     $this->db->select("staff.FirstName, staff.MiddleName, staff.LastName, staff.NickName, SalaryIncrease.IncreasedDate, SalaryIncrease.Comment, position.Title, team.TeamName");
	     $this->db->from('staff');
         $this->db->join('staffcontract','staff.StaffID = staffcontract.StaffID');
         $this->db->join('SalaryIncrease','staffcontract.StaffContractID = SalaryIncrease.StaffContractID');
         $this->db->join('position', 'position.PositionID = staffcontract.PositionID');
         $this->db->join('team', 'team.TeamID = staffcontract.Team');
         $this->db->where("MONTH(SalaryIncrease.IncreasedDate) = MONTH(CURDATE()) AND YEAR(SalaryIncrease.IncreasedDate) = YEAR(CURDATE())");
	     $this->db->order_by('staffcontract.CreatedDate','DESC');
	     $Q = $this->db->get();
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	     }
	     $Q->free_result();    
	     return $data; 	
    }
    
    function getStaffTrainiing($type = null)
    {
        $data = array();
        $this->db->select("sr.RTType, sr.DateRTraining, sr.PlaningTime, sr.TrainingClass, sr.Duration, sr.Comment, qt.QuaterPlan, course.CourseID, course.Topic, staff.FirstName, staff.MiddleName, staff.LastName, staff.NickName");
	    $this->db->from('staffrectraining AS sr');
	    $this->db->join('staff','staff.StaffID = sr.StaffID');
	    $this->db->join('quaterplan AS qt', 'qt.QPID = sr.PlaningTime','left');
	    $this->db->join('course', 'course.CourseID = sr.CourseID');
	    $this->db->where('sr.RTActive', 1); 
        if($type != null && $type != '')
        {
            $this->db->where('sr.RTType', $type);    
        }
        $Q = $this->db->get();
        if ($Q->num_rows() > 0){
           foreach ($Q->result_array() as $row){
             $data[] = $row;
           }
         }
         $Q->free_result();    
         return $data; 	
    }
    
    function getStaffDesirableTrainiing($course = 0)
    {
        $data = array();
        $this->db->select("sd.ID, sd.StaffID, course.Topic, course.CourseID,sd.Comment, sd.DateTraining, staff.FirstName, staff.MiddleName, staff.LastName, staff.NickName");
	    $this->db->from('staffdeserabletraining AS sd');
	    $this->db->join('staff','staff.StaffID = sd.StaffID');
	    $this->db->join('course', 'course.CourseID = sd.CourseID');
        if($course > 0)
        {
            $this->db->where('course.CourseID', $course);    
        }
        $Q = $this->db->get();
        if ($Q->num_rows() > 0){
           foreach ($Q->result_array() as $row){
             $data[] = $row;
           }
         }
         $Q->free_result();    
         return $data; 	
    }
    
    function getStaffsNotReceiveTraining($team = 0){
	     $data = array();
	     $this->db->select('staff.StaffID, staff.FirstName, staff.MiddleName, staff.LastName, staff.NickName, staff.StaffType, position.Title, user.UserId,
				team.TeamName, staff.CurrentAddress,staff.PhoneNumber,staff.SkypeID,staff.Email, staff.Comment, staff.Photo, location.Location');
	     $this->db->from('staff');
	     $this->db->join('position','position.PositionID = staff.PositionID','left');
	     $this->db->join('team', 'staff.TeamID = team.TeamID','left');
         $this->db->join('user', 'user.StaffId = staff.StaffID', 'left');
         $this->db->join('location','staff.LocationId = location.LocationID','left');
         $this->db->where("(staff.StaffID NOT IN (SELECT StaffID FROM staffrectraining WHERE RTActive = 1))"); 
         if($team > 0)
         {
            $this->db->where('team.TeamID', db_clean($team));
         }
	     $this->db->order_by('staff.CreatedDate', 'DESC');
	     $Q = $this->db->get();
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	     }
	     $Q->free_result();    
	     return $data; 	
	}
}